#include "Thread.hpp"

//线程分离和局部存储
// __thread int g_val = 100;//线程局部存储__thread  给每个线程都来一个变量

// void* start_routine(void* args)
// {
//     char* name = (char*)args;
//     int cnt = 10;
//     while (true)
//     {
//         cout << name << " is running" << " g_val = " << g_val << " &g_val = " << &g_val << endl;
//         g_val++;
//         sleep(1);
//     }
// }

// int main()
// {
//     pthread_t tid;
//     pthread_create(&tid, nullptr, start_routine, (void*)"thread1");
//     while (true)
//     {
//         cout << "main thread" << " is running" << " g_val = " << g_val << " &g_val = " << &g_val << endl;
//         g_val++;
//         sleep(1); 
//     }
//     //pthread_detach(tid);//线程分离 主线程无需等待从线程 从线程结束后由os回收
//     pthread_join(tid, nullptr);
//     return 0;
// }

//利用原生线程库封装实现thread
void* func(void* args)
{
    char* msg = (char*)args;
    cout << msg << endl;
}

int main()
{
    Thread t1 = Thread(func, (void*)"check", 1);
    Thread t2 = Thread(func, (void*)"upload", 2);
    Thread t3 = Thread(func, (void*)"download", 3);
    t1.join();
    t2.join();
    t3.join();
    return 0;
}